<?php

class DotDatabaseRenderer {

	function Render( &$oConfiguration, &$oDatabase ) {

		$sDatabaseText  = DotDatabaseRenderer::RenderHeader( $oConfiguration );
		$sDatabaseText .= DotDatabaseRenderer::RenderTables( $oConfiguration, $oDatabase );
		$sDatabaseText .= DotDatabaseRenderer::RenderForeignKeys( $oConfiguration, $oDatabase );
		$sDatabaseText .= DotDatabaseRenderer::RenderFooter( $oConfiguration );

		return $sDatabaseText;

	}
	
	function RenderTables( &$oConfiguration, &$oDatabase ) {

		$sTablesText = '';
		foreach( $oDatabase->GetTables() as $oThisTable ) {
			$sTablesText .= DotTableRenderer::Render( $oConfiguration, $oThisTable );
		}	
		return $sTablesText;	
	}
	
	function RenderForeignKeys( &$oConfiguration, &$oDatabase ) {

		$sKeysText = '';
		if ( $oConfiguration->GetProperty( 'ShowForeignKeys' ) ) {
			foreach( $oDatabase->GetForeignKeys() as $oThisForeignKey ) {
				$sKeysText .= DotForeignKeyRenderer::Render( $oConfiguration, $oThisForeignKey );
			}
		}	
		return $sKeysText;
	}
	
	function RenderHeader( &$oConfiguration ) {
	
		return 'graph table_definitions{'. "\n" .
				'	node[ shape=record fontname=' . $oConfiguration->GetProperty( 'TableFontFamily' ) . ' fontsize=' . $oConfiguration->GetProperty( 'TableFontSize' ) . '];'. "\n" .
				'	edge[ arrowhead=invodot fontname=' . $oConfiguration->GetProperty( 'KeyFontFamily' ) . ' fontsize=' . $oConfiguration->GetProperty( 'KeyFontSize' ) . '];'. "\n" .
				'	overlap=false;'. "\n" .
				'	splines=' . ( $oConfiguration->GetProperty( 'CurvedKeys' )?'true':'false' ) . ';' . "\n";
	}
	
	function RenderFooter( &$oConfiguration ) {
		return '}';
	}
}

require_once( 'DotTableRenderer.php' );
require_once( 'DotForeignKeyRenderer.php' );

?>
